import urllib2
import time
from HTMLParser import HTMLParser








def requestURL(url):
   #Setup headers to spoof Mozilla
   dat = None
   ua="Mozilla/5.0 (Windows; U; Windows NT 5.2; en-US; rv:1.9.1.4)Gecko/20091007 Firefox/3.5.4"
   head = {'User-agent': ua}

   errorcount = 0

   #Get page
   req = urllib2.Request(url, dat, head)
   try:
       response = urllib2.urlopen(req)
   except urllib2.HTTPError, e:
       if errorcount < 1:
           errorcount = 1
           print "Request failed, retrying in " + str(delay) + " seconds"
           time.sleep(int(delay)) 
           response = urllib2.urlopen(req)
   except urllib2.URLError, e:
       if errorcount < 1:
           errorcount = 1
           print "Request failed, retrying in " + str(delay) + " seconds"
           time.sleep(int(delay))
           response = urllib2.urlopen(req)

   return response.read()


def logMsg(msg):
   tstamp = time.localtime()
   y = str(tstamp[0])
   m = str(tstamp[1])
   d = str(tstamp[2]) 
   h = str(tstamp[3])
   mi = str(tstamp[4])
   s = str(tstamp[5]) 
   n = "lazylist.log"
   infile = open(n, "a")
#   finalMsg = "["+y+m+d+ " "+h+mi+s+ "] " + msg + "\n"  % (y,m,d,h,mi,s,msg)
   finalMsg = "[%s_%s_%s %s:%s:%s] %s \n"  % (y,m,d,h,mi,s,msg)
   infile.write(finalMsg)
   print finalMsg
   infile.close()

